import { mapGetters } from 'vuex'
import contentHeader from '@components/headers/content'
import pageHeader from '@components/headers/page'
import iconSvg from '@/components/icon-svg'

import storage from '@utils/storage'
import appMixins from '@light-app/mixins'

export const installPublicComponents = (Vue) => {
    Vue.component('pageHeader', pageHeader)
    Vue.component('contentHeader', contentHeader)
    Vue.component('icon-svg', iconSvg)
}

export const publicMixin = {
    computed: {
        ...mapGetters({
            $config: 'config',
            $user: 'user',
            $loading: 'loading'
        }),
        $storage: () => storage
    },
    methods: {
        $linkToHome(baseRoute) {
            if (process.env.NODE_ENV === 'development') {
                window.location = window.location.origin
            } else {
                window.location = window.location.origin + '/' + baseRoute
            }
        },
        $showLoading() {
            this.$store.commit('setLoading', true)
        },
        $hideLoading() {
            this.$store.commit('setLoading', false)
        }
    }
}

export default (Vue) => {
    installPublicComponents(Vue)

    Vue.mixin(publicMixin)

    appMixins.forEach(m => {
        Vue.mixin(m)
    })

}